package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.MarketIssue;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.admin.IssueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description
 * @Author klw
 * @Data 2022/11/20 下午10:40
 */

@RestController
@RequestMapping("admin/issue")
public class IssueController {

    @Autowired
    IssueService issueService;

    @GetMapping("list")  //list 接口 列表
    public BaseRespVo<CommonData>list(String question, BasePageInfo basePageInfo){
        CommonData<MarketIssue> query = issueService.query(question,basePageInfo);

        return BaseRespVo.ok(query);
    }

    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody MarketIssue marketIssue){
        issueService.delete(marketIssue);

        return BaseRespVo.ok();
    }

    @PostMapping("create")
    public BaseRespVo create(@RequestBody MarketIssue marketIssue){
        MarketIssue marketIssue1 = issueService.createIssue(marketIssue);
        if(null == marketIssue1){
            return BaseRespVo.error(601,"已有此问题");
        }
        return BaseRespVo.ok(marketIssue1);
    }

    @PostMapping("update")
    public BaseRespVo update(@RequestBody MarketIssue marketIssue){
        MarketIssue marketIssue1 = issueService.updateIssue(marketIssue);

        return BaseRespVo.ok(marketIssue1);
    }
}
